package com.zy.hashequal;

/**
 * @Author Gong
 * @Description 订单类
 * @dATE 2021/11/24 11:36
 **/
public class Order {
    private int orderId; //订单id
    private String orderName; //订单名

    @Override
    public int hashCode() {
        return 1;
    }

    @Override
    public boolean equals(Object obj) {
        if(obj instanceof Order){
            Order order = (Order) obj;
            if(order.orderId == this.getOrderId() && null != order.getOrderName() && order.getOrderName().equals(this.getOrderName())){
                return true;
            }
        }
        return false;
    }

    public Order(int orderId, String orderName) {
        this.orderId = orderId;
        this.orderName = orderName;
    }

    public int getOrderId() {
        return orderId;
    }

    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }

    public String getOrderName() {
        return orderName;
    }

    public void setOrderName(String orderName) {
        this.orderName = orderName;
    }

    public static void main(String[] args) {
        Order o1 = new Order(1,"1");
        Order o2 = new Order(1,"1");

        System.out.println(o1.equals(o2));
        System.out.println(o1.hashCode());
        System.out.println(o2.hashCode());
        System.out.println(o1 == o2);

    }
}
